package com.biodiv.common.message;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 天权
 */
public abstract class Message implements Serializable {

    public static Class<? extends Message> getMessageClass(int messageType) {
        return messageClasses.get(messageType);
    }

    private int sequenceId;

    private int messageType;

    public void setMessageType(int messageType) {
        this.messageType = messageType;
    }

    public int getSequenceId() {
        return sequenceId;
    }

    public void setSequenceId(int sequenceId) {
        this.sequenceId = sequenceId;
    }

    public abstract int getMessageType();

    public static final int LoginRequestMessage = 0;
    public static final int LoginResponseMessage = 1;
    public static final int ServiceRegistrationMessage = 2;
    public static final int PullServiceRequestMessage = 3;
    public static final int PullServiceResponseMessage = 4;
    public static final int DeleteInstanceMessage = 5;
    public static final int ServiceUpdateMessage = 6;

    private static final Map<Integer, Class<? extends Message>> messageClasses = new HashMap<>();

    static {
        messageClasses.put(LoginRequestMessage, LoginRequestMessage.class);
        messageClasses.put(LoginResponseMessage, LoginResponseMessage.class);
        messageClasses.put(ServiceRegistrationMessage, ServiceRegistrationMessage.class);
        messageClasses.put(PullServiceRequestMessage, PullServiceRequestMessage.class);
        messageClasses.put(PullServiceResponseMessage, PullServiceResponseMessage.class);
        messageClasses.put(DeleteInstanceMessage, DeleteInstanceMessage.class);
        messageClasses.put(ServiceUpdateMessage, ServiceUpdateMessage.class);
    }


}
